﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using SharpMap.Presentation.Wpf.Utility;
using System.Windows;

using System.Windows.Data;

namespace SharpMap.Wpf
{
    public class ContentLayerItem : ContentControl
    {
        public static readonly DependencyProperty WorldXProperty 
            = GeoPanel.WorldXProperty.AddOwner(
            typeof(ContentLayerItem)
            ,new FrameworkPropertyMetadata
                (
                    double.NaN,
                    FrameworkPropertyMetadataOptions.AffectsParentArrange
                    | FrameworkPropertyMetadataOptions.Inherits
                    , WorldLocationPropertyChanged
                )
            );
        public static readonly DependencyProperty WorldYProperty 
            = GeoPanel.WorldYProperty.AddOwner(
            typeof(ContentLayerItem),
              new FrameworkPropertyMetadata
                (
                    double.NaN,
                    FrameworkPropertyMetadataOptions.AffectsParentArrange
                    | FrameworkPropertyMetadataOptions.Inherits
                    , WorldLocationPropertyChanged
                )
            );

       
        public double WorldX
        {
            get{return GeoPanel.GetWorldX(this);}
            set{GeoPanel.SetWorldX(this,value);}
        }
        public double WorldY
        {
            get{return GeoPanel.GetWorldY(this);}
            set{GeoPanel.SetWorldY(this,value);}
        }







  

        static void ViewLocationPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            ContentLayerItem This = target as ContentLayerItem;
        }

       

        static void WorldLocationPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            ContentLayerItem This = target as ContentLayerItem;
        }


   

    
 

        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);
            UIElement uiElement = newContent as UIElement;
            if (uiElement != null)
            {
                WorldX = GeoPanel.GetWorldX(uiElement);
                WorldY = GeoPanel.GetWorldY(uiElement);
                uiElement.ClearValue(WorldXProperty);
                uiElement.ClearValue(WorldYProperty);
 

            }
        }

        
    }
}
